import { _decorator, Component, instantiate, AudioSource, assert, assetManager, resources, AudioClip } from "cc";
const { ccclass, property } = _decorator;

@ccclass("AudioController")
export class AudioController extends Component {
  _audioSource: AudioSource = null;
  clipList: AudioClip[] = [];
  _index: number = 0;
  onLoad() {
    const audioSource = this.node.getComponent(AudioSource)!;
    resources.load(["mp3/dong", "mp3/papa"], AudioClip, (err, data) => {
      console.log("err", err);
      console.log("data", data);
      this.clipList = data;
      this._audioSource = audioSource;
      this._audioSource.clip = this.clipList[this._index];
      audioSource.node.on(AudioSource.EventType.ENDED, this.onAudioEnded, this);
    });
  }
  play() {}
  onAudioEnded() {
    this._index++;
    this._audioSource.clip = this.clipList[this._index];
    this._audioSource.play();
  }
}
